"use client"
import React , { useEffect, useState }from 'react'
import { Input, Button, DatePicker  } from 'antd';
import { SearchOutlined } from '@ant-design/icons';
import { request } from '@/lib/request';

const page = () => {
    // 股票数据和开始时间存储
    const [startData, setStartData] = useState('');
    const [sharesCode, setSharesCode] = useState('');

    // 处理用户搜索股票数据图表
    const reloadCharts = async (obj) => {
      const response = await request.post('http://127.0.0.1:8000/getsharschats', obj);
      refreshIframes()
      // console.log(response);
    };
    const handleOk = () => {
      if (startData.trim() && sharesCode.trim()){
        reloadCharts({ startData, sharesCode });
      }
    };

    // 刷新iframe
    const refreshIframes = () => {
      document.getElementById('iframe1').contentWindow.location.reload();
      document.getElementById('iframe2').contentWindow.location.reload();
      document.getElementById('iframe3').contentWindow.location.reload();
      document.getElementById('iframe4').contentWindow.location.reload();
    }
    // 选择时间框
  const onChange = (date, dateString) => {
    console.log(date, dateString);
    setStartData(dateString)
  };
  return (
    <div>
      <div>
        默认显示为上一次可视化结果
      {/* <Input placeholder="开始时间:20240430" value={startData} onChange={(e) => setStartData(e.target.value)}/> */}
      <DatePicker format={{
        format: 'YYYYMMDD',
        // type: 'mask',
      }}
      onChange={onChange}
      style={{width:"100%"}}
      placeholder="开始时间:20240430"/>
      <Input placeholder="股票编码:000004" value={sharesCode} onChange={(e) => setSharesCode(e.target.value)}/>
      <Button type="primary" icon={<SearchOutlined />} style={{width:"100%"}} onClick={handleOk}>
        查询
      </Button>
      </div>
      <iframe id="iframe1" src="/bulinxian.html" title="bulinxian" width="49%" height="500px" />
      <iframe id="iframe2" src="/kdj.html" title="kdj" width="50%" height="500px" />
      <iframe id="iframe3" src="/macd.html" title="macd" width="49%" height="500px" />
      <iframe id="iframe4" src="/macd.htmljunxian.html" title="macd" width="50%" height="500px" />
    </div>
  )
}

export default page
